package com.sh.数组;

/**
 * @Auther: sh
 * @Version 1.0
 * @Description:
 */
public class 有序数组的平方 {
    public static void main(String[] args) {

    }

    public static int[] sortedSquares(int[] nums) {
        int left = 0;
        int right = nums.length-1;
        int[] ints = new int[nums.length];
        int pos = right ;
        while (left<=right){
            if (nums[left] * nums[left] > nums[right] * nums[right]) {
                ints[pos--] = nums[left] * nums[left];
                left++;
            } else {
                ints[pos--] = nums[right] * nums[right];
                right--;
            }

        }
        return ints;

    }

}

